﻿#ifndef CONTACTTREE_H
#define CONTACTTREE_H

#include <QTreeWidget>
#include <QMap>
#include "contactuser.h"

class LiteDb;

class ContactItemView : public QTreeWidget
{
    Q_OBJECT
public:
    explicit ContactItemView(QWidget *parent = Q_NULLPTR);
    static QString getName(const QVariantHash &contact, bool notEmpty);
    const ContactUser *findUser(qint64 uid) const;

    void handle_contact_list(const QList<QVariantHash> *objs);
    ContactUser *handle_my_contact(QVariantHash &contact);
    void refreshView();

    void handle_msg_list(const QList<QVariantHash> &msg_list);
    void handle_search(const QString& keyword);
protected:
    QModelIndexList selectedIndexes() const;
private:
    ContactUser *handle_contact(QVariantHash &contactObj, QMap<qint64, ContactUser> &contacts, QList<qint64> *delContactList, QMap<qint64, QVariant> *db_contact, LiteDb *db);
    void handle_contact_list(const QList<QVariantHash> &objs, QMap<qint64, QVariant> *db_contact, LiteDb *db);
    QMap<qint64, ContactUser> map_contact;
    QString searchword;
    qint64 my_p_org_id;
};

#endif // CONTACTTREE_H
